/**
 * 添加或者修改页面
 */
var GcgWsjdInfoDlg = {
    data: {
        gcgWsjdId: "",
        gcgProjectId: "",
        yaoma: "",
        mingcheng: "",
        dizhiSheng: "",
        dizhiShengView: "",
        dizhiShi: "",
        dizhiShiView: "",
        dizhiXianqu: "",
        dizhiXianquView: "",
        dizhiXiangxi: "",
        pinpai: "",
        guishu: "",
        mdTel: "",
        lxrName: "",
        lxrTel: "",
        jsTel: "",
        pinlei: "",
        mdYysj: "",
        isTcw: "",
        tcwPrice: "",
        renjunPrice: "",
        farenXingming: "",
        yhkName: "",
        yhkHao: "",
        isFapiao: "",
        isYouhui: "",
        farenSfzPic1: "",
        farenSfzPic2: "",
        farenSfzPic3: "",
        dzSfzPic1: "",
        dzSfzPic2: "",
        dzSfzPic3: "",
        yingyeZhizhao: "",
        shipinXkz: "",
        zfbShouquan: "",
        mentouPics: "",
        neijingPics: "",
        shStatus: "",
        createTime: "",
        createUser: "",
        updateTime: "",
        updateUser: "",
        gcgWsjdYinhangkaId: ""
    }
};

layui.use(['form', 'admin', 'ax','laydate','upload','formSelects'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    /**
     * 检索区域
     */
    var qyAjax = new $ax("/area/getAreaByType");
    qyAjax.set("type", 2);
    var qyResult = qyAjax.start();
    $.each(qyResult, function (index, data) {
        $("#dizhiSheng").append("<option value='" + data.id + "'>" + data.simpleName + "</option>");
    });
    form.render('select');
    form.on('select(dizhiSheng)', function (data) {
        var provinceId = data.value;
        isHasXianqu = false;
        if (provinceId == "") {
            $("#dizhiShi").html("");
            $("#dizhiShi").append("<option value=''>全部</option>");
            form.render('select');
        } else {
            var qyAjax = new $ax("/area/getAreaByPid");
            qyAjax.set("pid", provinceId);
            var qyResult = qyAjax.start();
            $("#dizhiShi").html("");
            $("#dizhiShi").append("<option value=''>全部</option>");
            $.each(qyResult, function (index, data) {
                $("#dizhiShi").append("<option value='" + data.id + "'>" + data.simpleName + "</option>");
            });
            form.render('select');
        }
    });
    var isHasXianqu = false;
    form.on('select(dizhiShi)', function (data) {
        isHasXianqu = false;
        var cityId = data.value;
        if (cityId == "") {
            $("#dizhiXianqu").html("");
            $("#dizhiXianqu").append("<option value=''>全部</option>");
            form.render('select');
        } else {
            var qyAjax = new $ax("/area/getAreaByPid");
            qyAjax.set("pid", cityId);
            var qyResult = qyAjax.start();
            $("#dizhiXianqu").html("");
            $("#dizhiXianqu").append("<option value=''>全部</option>");
            $.each(qyResult, function (index, data) {
                $("#dizhiXianqu").append("<option value='" + data.id + "'>" + data.simpleName + "</option>");
                isHasXianqu = true;
            });

            form.render('select');
        }
    });


    //YYJL
    var ajax1 = new $ax(Feng.ctxPath + "/project/selectYyjlList", function (data) {
        var sb;
        for(let i = 0; i < data.length; i++) {
            sb+='<option value="'+data[i].tel+'">' + data[i].yyjl + '</option>';
        }
        $("#yyjl").append(sb);
        form.render();
    }, function (data) {
        Feng.error(data.responseJSON.message);
    });
    ajax1.start();

    //DD
    form.on('select(yyjl)', function(data){
        $('#dd option').not('option:first').remove();
        if(data.value!=''){
            var ajax1 = new $ax(Feng.ctxPath + "/project/selectDdList", function (data) {
                var sb;
                for(let i = 0; i < data.length; i++) {
                    sb+='<option value="'+data[i].tel+'">' + data[i].dd + '</option>';
                }
                $("#dd").append(sb);
                form.render();
            }, function (data) {
                Feng.error(data.responseJSON.message);
            });
            ajax1.set("phone",data.value);
            ajax1.start();
        }
    });


    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/wsjd/addItem", function (data) {
            Feng.success("添加成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.set("dizhiShengView",$("#dizhiSheng option:selected").text());
        ajax.set("dizhiShiView",$("#dizhiShi option:selected").text());
        ajax.set("dizhiXianquView",$("#dizhiXianqu option:selected").text());
        ajax.start();

        return false;
    });


});